package cn.sciento.wechat.enterprise.service.impl;

import com.alibaba.fastjson.JSON;
import javax.annotation.Resource;
import cn.sciento.wechat.enterprise.dto.AppChatCreateResultDTO;
import cn.sciento.wechat.enterprise.dto.AppChatDTO;
import cn.sciento.wechat.enterprise.dto.AppChatUpdateDTO;
import cn.sciento.wechat.enterprise.dto.DefaultResultDTO;
import cn.sciento.wechat.enterprise.dto.FileMessageDTO;
import cn.sciento.wechat.enterprise.dto.ImageMessageDTO;
import cn.sciento.wechat.enterprise.dto.MarkdownMessageDTO;
import cn.sciento.wechat.enterprise.dto.MessageSendResultDTO;
import cn.sciento.wechat.enterprise.dto.MiniProgramNoticeMessageDTO;
import cn.sciento.wechat.enterprise.dto.NewsMessageDTO;
import cn.sciento.wechat.enterprise.dto.TaskCardMessageDTO;
import cn.sciento.wechat.enterprise.dto.TextCardMessageDTO;
import cn.sciento.wechat.enterprise.dto.TextMessageDTO;
import cn.sciento.wechat.enterprise.dto.VideoMessageDTO;
import cn.sciento.wechat.enterprise.dto.VoiceMessageDTO;
import cn.sciento.wechat.enterprise.service.WechatCorpMessageService;
import org.springframework.http.HttpEntity;
import org.springframework.web.client.RestTemplate;

public class WechatCorpMessageServiceImpl implements WechatCorpMessageService {
  @Resource(name = "wdRestTemplate")
  protected RestTemplate restTemplate;
  
  public MessageSendResultDTO sendTextMsg(TextMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendImageMsg(ImageMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendVoiceMsg(VoiceMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendVideoMsg(VideoMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendFileMsg(FileMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendTextCardMsg(TextCardMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendNewsMsg(NewsMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendMarkdownMsg(MarkdownMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendMiniProgramNoticeMsg(MiniProgramNoticeMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public MessageSendResultDTO sendTaskCardMsg(TaskCardMessageDTO messageDTO, String accessToken) {
    return (MessageSendResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(messageDTO)), MessageSendResultDTO.class);
  }
  
  public AppChatCreateResultDTO createAppChat(AppChatCreateResultDTO appChatCreateResultDTO, String accessToken) {
    return (AppChatCreateResultDTO)this.restTemplate.postForObject(" https://qyapi.weixin.qq.com/cgi-bin/appchat/create?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(appChatCreateResultDTO)), AppChatCreateResultDTO.class);
  }
  
  public DefaultResultDTO updateAppChat(AppChatUpdateDTO appChatUpdateDTO, String accessToken) {
    return (DefaultResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/appchat/update?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(appChatUpdateDTO)), DefaultResultDTO.class);
  }
  
  public AppChatDTO getAppChat(String chatid, String accessToken) {
    return (AppChatDTO)this.restTemplate.getForObject("https://qyapi.weixin.qq.com/cgi-bin/appchat/get?access_token=" + accessToken + "&chatid=" + chatid, AppChatDTO.class);
  }
  
  public DefaultResultDTO sendAppChat(Object object, String accessToken) {
    return (DefaultResultDTO)this.restTemplate.postForObject("https://qyapi.weixin.qq.com/cgi-bin/appchat/send?access_token=" + accessToken, new HttpEntity(JSON.toJSONString(object)), DefaultResultDTO.class);
  }
}
